package maiyatian.videolive.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import maiyatian.videolive.ConstentInfo;
import maiyatian.videolive.IActivity;
import maiyatian.videolive.R;
import maiyatian.videolive.fragment.WebviewFragment;

/**
 * Created by 王中阳 on 2016/5/10.
 */
@ContentView(R.layout.activity_webview)
public class WebviewActivity extends IActivity implements View.OnClickListener {
    public static final String TAG = "WebviewActivity";
    //fragment初始化及实例化
    WebviewActivity mycontext;
    ActionBar ab;
    @ViewInject(R.id.titleBar)
    TextView titleBar;
    @ViewInject(R.id.back)
    ImageView back;
    private String IntentURL;
    Fragment fragment = null;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        back.setOnClickListener(this);
        mPageTo = WebviewActivity.this.getIntent().getStringExtra(IActivity.PAGETO);
        setIntentURL(mPageTo);
        switchFragment(mPageTo);
    }

    private void switchFragment(String mPageTo) {
        fragment = WebviewFragment.newInstance();
        switch (mPageTo) {
            case ConstentInfo.USER_AUTH:
                titleBar.setText(getResources().getString(R.string.appAuth));
                break;
            case ConstentInfo.USER_HOME:
                titleBar.setText(getResources().getString(R.string.personHome));
                break;
            case ConstentInfo.USER_LEVEL:
                titleBar.setText(getResources().getString(R.string.appLevel));
                break;
            case ConstentInfo.HOME:
                titleBar.setText(getResources().getString(R.string.home));
                break;
            case ConstentInfo.Chair_TREATY:
                titleBar.setText(getResources().getString(R.string.chairTreaty));
                break;
            case ConstentInfo.ABOUT_COMMUNITYCONVENTION:
                titleBar.setText(getResources().getString(R.string.communityConvention));
                break;
            case ConstentInfo.ABOUT_CONTACTUS:
                titleBar.setText(getResources().getString(R.string.contactUs));
                break;
            case ConstentInfo.ABOUT_PRIVACYPOLICY:
                titleBar.setText(getResources().getString(R.string.privacyPolicy));
                break;
            case ConstentInfo.ABOUT_SERVICETRRMS:
                titleBar.setText(getResources().getString(R.string.serviceTerms));
                break;
            case ConstentInfo.HELP:
                titleBar.setText(getResources().getString(R.string.help));
                break;
            case ConstentInfo.FEEDBACK:
                titleBar.setText(getResources().getString(R.string.feedback));
                break;
            case ConstentInfo.ARTICAL:
                titleBar.setText(getResources().getString(R.string.artical));
                break;
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.frameWebview, fragment).commit();
        }
    }

    public String getIntentURL() {
        return IntentURL;
    }

    public void setIntentURL(String intentURL) {
        IntentURL = intentURL;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                this.finish();
                break;
        }
    }
}
